#!/usr/bin/env bash
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

if [ -z "$1" ]; then
    echo "usage: stress.sh input.abc [output.abc]"
    exit 1
fi

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

if [ ! -d "$OUT_DIR" ]; then
    echo "No such directory (OUT_DIR): $OUT_DIR"
fi

ABCKIT="$OUT_DIR/arkcompiler/runtime_core/abckit"
STRESS_PLUGIN="$OUT_DIR/arkcompiler/runtime_core/libabckit_stress_plugin.so"

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:\
$OUT_DIR/arkcompiler/runtime_core:\
$OUT_DIR/arkcompiler/ets_runtime:\
$OUT_DIR/arkcompiler/ets_frontend:\
$OUT_DIR/thirdparty/icu:\
$OUT_DIR/thirdparty/zlib"

set -x
"$ABCKIT" --plugin-path "$STRESS_PLUGIN" "$@"
